home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 6 / develop 6 code / TCP / NewsWatcher / NewsWatcher 2.0d15 source / source / font.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-30  |  2.5 KB  |  109 lines  |  [TEXT/KAHL]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     font.c
  4.  
  5.     This module handles the Font and Size menu commands.
  6.     
  7.     Portions copyright © 1990, Apple Computer.
  8.     Portions copyright © 1993, Northwestern University.
  9.  
  10. ----------------------------------------------------------------------------*/
  11.  
  12. #include "glob.h"
  13. #include "font.h"
  14. #include "menus.h"
  15. #include "open.h"
  16. #include "resize.h"
  17. #include "util.h"
  18. #include "wind.h"
  19.  
  20.  
  21. /*    UpdateFontInfo updates the font information for a window */
  22.  
  23. static void UpdateFontInfo (WindowPtr wind)
  24. {
  25.     FontInfo fontInfo;
  26.     TWindow **info;
  27.     ListHandle theList;
  28.     TEHandle theTE;
  29.     Point newSize;
  30.         
  31.     GetFontInfo(&fontInfo);
  32.     info = (TWindow**)GetWRefCon(wind);
  33.     
  34.     switch ((**info).kind) {
  35.         case kFullGroup:
  36.         case kNewGroup:
  37.         case kUserGroup:
  38.         case kSubject:
  39.             theList = (**info).theList;
  40.             newSize.h = (**theList).cellSize.h;
  41.             newSize.v = fontInfo.ascent+fontInfo.descent+fontInfo.leading;
  42.             LCellSize(newSize,theList);
  43.             CalcWindowHCoords(wind);
  44.             break;
  45.         case kArticle:
  46.         case kMiscArticle:
  47.         case kMailMessage:
  48.         case kPostMessage:
  49.             theTE = (**info).theTE;
  50.             (**theTE).txFont = wind->txFont;
  51.             (**theTE).txFace = wind->txFace;
  52.             (**theTE).txMode = wind->txMode;
  53.             (**theTE).txSize = wind->txSize;
  54.             (**theTE).lineHeight = 
  55.                 fontInfo.ascent+fontInfo.descent+fontInfo.leading;
  56.             (**theTE).fontAscent = fontInfo.ascent;
  57.             CalcPanelHeight(wind);
  58.             break;
  59.     }
  60.     SizeContents(wind);
  61.     SetWindowNeedsZooming(wind);
  62. }
  63.  
  64. void FontWasChanged (Boolean listFont)
  65. {
  66.     WindowPtr    wind;
  67.     WindowPeek    peek;
  68.     TWindow **    info;
  69.     EWindowKind kind;
  70.     short        fontID, fontSize;
  71.     Boolean        changeWind;
  72.     GrafPtr        savePort;
  73.  
  74.     /* Figure out the new font ID and size */
  75.     if (listFont) {
  76.         GetFNum(gPrefs.listFont, &fontID);
  77.         fontSize = gPrefs.listSize;
  78.     } else {
  79.         GetFNum(gPrefs.textFont, &fontID);
  80.         fontSize = gPrefs.textSize;
  81.     }
  82.  
  83.     /* Loop through all the windows and see if they need updating */ 
  84.     GetPort(&savePort);
  85.     wind = FrontWindow();
  86.     while (wind != nil) {
  87.         peek = (WindowPeek)wind;
  88.         if (!IsStatusWindow(wind) && IsAppWindow(wind)) {
  89.             info = (TWindow**)GetWRefCon(wind);
  90.             kind = (**info).kind;
  91.             changeWind = false;
  92.             if (listFont) {
  93.                 changeWind = (kind <= kSubject);
  94.             } else {
  95.                 changeWind = (kind >= kArticle && kind <= kPostMessage);
  96.             }
  97.             if (changeWind) {
  98.                 if (!listFont) (**(**info).theTE).txFont = fontID;
  99.                 SetPort(wind);
  100.                 TextFont(fontID);
  101.                 TextSize(fontSize);
  102.                 UpdateFontInfo(wind);
  103.                 InvalRect(&wind->portRect);
  104.             }
  105.         }
  106.         wind = (WindowPtr)peek->nextWindow;
  107.     }
  108. }
  109.